package evostar.exception;


import evostar.result.CodeMsg;
import evostar.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class ExceptionsHandler {
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result<Object> handler(Exception e) {
        if (e instanceof ServerException) {
            ServerException exception = (ServerException) e;
            return Result.error(exception.getMsg());
        } else {
            return Result.error(CodeMsg.SERVER_ERROR);
        }

    }
}
